package com.fyzk.adapter;

import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fyzk.activity.lottery.recommend_order.RankBean;
import com.fyzk.utils.StringUtils;
import com.tyjc.lottery.R;

public class RankAdapter extends BaseQuickAdapter<RankBean, BaseViewHolder> {
    //1连红榜，=2命中榜，=3盈利榜，=4人气榜
    private int mType;

    public RankAdapter(int type) {
        super(R.layout.item_rank);
        this.mType = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, RankBean item) {
        @ColorRes int numberTextColor = R.color.black;
        @DrawableRes int boardImage = R.drawable.icon_no1;
        String redText = "0";
        switch (helper.getLayoutPosition()) {
            case 0:
                numberTextColor = R.color.color_no1;
                boardImage = R.drawable.icon_no1;
                break;
            case 1:
                numberTextColor = R.color.color_no2;
                boardImage = R.drawable.icon_no2;
                break;
            case 2:
                numberTextColor = R.color.color_no3;
                boardImage = R.drawable.icon_no3;
                break;
        }
        try {
            switch (mType) {
                case 1://连红榜
                    redText = String.valueOf(item.getEvenRed());
                    break;
                case 2://命中榜
                    redText = String.format("%.2f%%", item.getHitRatio() * 100);
                    break;
                case 3://盈利榜
                    redText = String.format("%.2f%%", Double.parseDouble(item.getProfitRatio()) * 100);
                    break;
                case 4://人气榜
                    redText = String.valueOf(item.getPopularity());
                    break;
            }
        } catch (NumberFormatException e) {
        }
        Glide.with(mContext)
                .load(boardImage)
                .into((ImageView) helper.getView(R.id.iv_board));
        Glide.with(mContext)
                .load(item.getUserPhotoUrl())
                .circleCrop()
                .error(R.drawable.rr_header_icon)
                .placeholder(R.drawable.rr_header_icon)
                .into((ImageView) helper.getView(R.id.iv_avatar));
        helper.setText(R.id.tv_number, String.valueOf(helper.getLayoutPosition() + 1))
                .setText(R.id.tv_name, StringUtils.formatBindMobile(item.getUserName()))
                .setText(R.id.tv_red_num, redText)
                .setTextColor(R.id.tv_number, mContext.getResources().getColor(numberTextColor))
                .setGone(R.id.tv_even_red, mType == 1)//1连红榜 时显示
                .setGone(R.id.iv_board, helper.getLayoutPosition() < 3)
        ;
    }
}
